import 'package:basic_library/src/widgets/pop_alert/q_invitation_sheet.dart';
import 'package:flutter/material.dart';

///
/// 第三方分享
///
class QShareSheet extends Dialog {
  final BuildContext buildContext;
  final List<UserInfoModel> dataList;
  final Function? onTap;

  const QShareSheet({
    Key? key,
    required this.buildContext,
    required this.dataList,
    this.onTap,
  }) : super(key: key);

  /// 取消对话框
  static hide(BuildContext context) {
    Navigator.of(context).pop();
  }

  /// 显示对话框
  void show() {
    // 用于在底部打开弹框的效果
    showModalBottomSheet(
      backgroundColor: Colors.transparent, // 重要
      context: buildContext,
      builder: (BuildContext context) {
        // 构建弹框中的内容
        return ShareContentView(
          dataList: dataList,
          tapCallback: onTap,
        );
      },
    );
  }
}

class ShareContentView extends StatefulWidget {
  final List<UserInfoModel> dataList;
  final Function? tapCallback;

  const ShareContentView({
    Key? key,
    required this.dataList,
    this.tapCallback,
  }) : super(key: key);

  @override
  _ShareContentViewState createState() => _ShareContentViewState();
}

class _ShareContentViewState extends State<ShareContentView> {
  @override
  Widget build(BuildContext context) {
    return buildBottomSheetWidget(context);
  }

  /// 底部弹出框的内容
  Widget buildBottomSheetWidget(BuildContext context) {
    return Container(
      height: 200,
      decoration: const BoxDecoration(
        color: Colors.white,
        borderRadius: BorderRadius.only(
          topLeft: Radius.circular(25.0),
          topRight: Radius.circular(25.0),
        ),
      ),
      child: Column(
        children: [
          const Padding(
            padding: EdgeInsets.symmetric(horizontal: 8, vertical: 16),
            child: Text(
              "分享",
              style: TextStyle(
                color: Color(0xFF36393D),
                fontSize: 18,
              ),
            ),
          ),
          Container(
            padding: const EdgeInsets.symmetric(horizontal: 16),
            height: 75,
            child: ListView.builder(
              scrollDirection: Axis.horizontal,
              itemCount: widget.dataList.length,
              itemBuilder: (BuildContext context, int index) {
                UserInfoModel e = widget.dataList[index];
                return InkWell(
                  child: Container(
                    margin: const EdgeInsets.symmetric(horizontal: 6),
                    child: Column(
                      children: <Widget>[
                        Padding(
                          padding: const EdgeInsets.fromLTRB(0.0, 3, 0.0, 3),
                          child: Image.asset(
                            e.url,
                            width: 44,
                          ),
                        ),
                        Text(e.name)
                      ],
                    ),
                  ),
                  onTap: () {
                    switch (e.name) {
                      case '微信':
                        debugPrint("微信");
                        break;
                      case '朋友圈':
                        debugPrint("朋友圈");
                        break;
                      case 'QQ':
                        debugPrint("QQ");
                        break;
                      case 'QQ空间':
                        debugPrint("QQ空间");
                        break;
                      case '微博':
                        debugPrint("微博");
                        break;
                    }
                    Navigator.pop(context);
                    widget.tapCallback!.call(e.name);
                  },
                );
              },
            ),
          ),
          const SizedBox(height: 16),
          commonButtonWidget(
            fontSize: 16,
            txt: "取消",
            onTap: () => Navigator.pop(context),
          ),
        ],
      ),
    );
  }

  Widget commonButtonWidget({
    required String txt,
    Color? fontColor,
    Color? backColor,
    double? fontSize,
    Function? onTap,
  }) {
    Color fontColor = const Color(0xFF19D88E);
    Color backColor = const Color(0xFF19D88E).withOpacity(0.2);
    double fontSize = 18;
    return Center(
      child: Material(
        // INK可以实现装饰容器
        child: Ink(
          // 用ink圆角矩形
          decoration: BoxDecoration(
            // 不能同时”使用Ink的变量color属性以及decoration属性，两个只能存在一个
            color: backColor,
            // 设置圆角
            borderRadius: const BorderRadius.all(
              Radius.circular(25.0),
            ),
          ),
          child: InkWell(
            // 圆角设置,给水波纹也设置同样的圆角
            // 如果这里不设置就会出现矩形的水波纹效果
            borderRadius: BorderRadius.circular(25.0),
            // 设置点击事件回调
            onTap: () {
              onTap!();
            },
            child: Container(
              width: 300.0,
              height: 36.0,
              // 设置child 居中
              alignment: const Alignment(0, 0),
              child: Text(
                txt,
                style: TextStyle(
                  color: fontColor,
                  fontSize: fontSize,
                ),
              ),
            ),
          ),
        ),
      ),
    );
  }
}
